﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Torch_Services
{
    public class FastMenuBll : IFastMenuBll
    {
        private IFastMenuDal _fastMenu;
        private IMapper _mapper;
        public FastMenuBll(IFastMenuDal fastMenu, IMapper mapper)
        {
            _fastMenu = fastMenu;
            _mapper = mapper;
        }

        public async Task<int> AddFastMenuAsync(string title, string link)
        {
            return await _fastMenu.AddAsync(new Fastmenu 
            {
                Title = title,
                Link = link,
            });
        }

        public async Task<int> DeleteFastMenuAsync(int id)
        {
            var data = await _fastMenu.QueryAsync(id);
            return data == null ? -1 : await _fastMenu.DeleteAsync(data);
        }

        public async Task<int> EditFastMenuAsync(int id, string title, string link)
        {
            var data = await _fastMenu.QueryAsync(id);
            if (data == null)
                return -1;
            data.Title = title;
            data.Link = link;
            return await _fastMenu.EditAsync(data);
        }

        public async Task<List<FastMenuDto>> GetFastMenuAllAsync()
        {
            var data = await _fastMenu.QueryAsync();
            return _mapper.Map<List<Fastmenu>,List<FastMenuDto>>(data);
        }

        public async Task<FastMenuDto> QueryFastMenuByIdAsync(int id)
        {
            var data = await _fastMenu.QueryAsync(id);
            return _mapper.Map<Fastmenu, FastMenuDto>(data);
        }

        public async Task<List<FastMenuDto>> QueryFastMenuByNameAsync(string title)
        {
            var data = await _fastMenu.QueryAsync(f => f.Title.Contains(title));
            return _mapper.Map<List<Fastmenu>, List<FastMenuDto>>(data);
        }
    }
}
